package com.mmall.concurrency.syncContainer;

import com.mmall.concurrency.annotations.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Vector;

@Slf4j
@NotThreadSafe
public class VoctorUnsafe {
    public static Vector<Integer> vector = new Vector<>();

    public static void main(String[] args) {
        while(true){
            //初始化数组向量容器
            for(int i = 0; i< 10; i++){
                vector.add(i);
            }
            // 定义两个线程，具有不同的操作
            Thread thread1 = new Thread(){
                public void run(){
                    for(int i = 0; i< vector.size(); i++){
                        vector.remove(i);
                    }
                }
            };

            Thread thread2 = new Thread(){
                public void run(){
                    for(int i = 0; i< vector.size(); i++){
                        vector.get(i);
                    }
                }
            };

            thread1.start();
            thread2.start();
        }
    }

}
